package com.mjk.common.web.getway.constns;


import com.mjk.common.base.error.IError;
import com.mjk.common.base.response.BeeResponse;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 网关 错误
 * @author mjk
 *
 */
@Getter
public enum GetWayError implements IError {
	RPC_EXCEPTION(-1013,"rpc异常"),
	IP_IS_NULL(-1012,"获取ip地址为空"),
	SOAP_REQ_ERROR(-1011,"SOAP 请求异常"),
	DATA_FORMAT_ERROR(-1010,"数据格式错误"),
	LICENSE_SUC(-1009,"license授权成功，重新请求"),
	LICENSE_TIMEOUT(-1008,"license过期"),
	LICENSE_ERROR(-1007,"license错误"),
	QPS_MORETHAN(-1006,"请求太频繁"),
	RESTF_URL_NO_METHOD(-1014,"参数中不存在method"),	
	RESTF_URL_NO_PROTOCAL(-1001,"restful 中 protocal 为空"),	
	MUST_PARAMS_IS_NULL(-1002,"必带参数没有"),
	AUTH_ERROR(-1003,"鉴权失败"),
	SESSION_TIMEOUT(-1004,"session过期 ,请从新登录"),
	CLOUD_VERSION_IS_ERROR(-1006,"cloud配置信息错误"),
	DUBBO_VERSION_IS_ERROR(-1005,"duboo配置信息错误"),
	SUC(1, "成功"),
	IS_VIEW_PRE_REQ(2,"页面请求前置拦截器")
	;
	private final Integer code;
	private final String msg;

	GetWayError(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public static String getMsg(int index) {
		for (GetWayError c : values()) {
			if (c.getCode() == index) {
				return c.msg;
			}
		}
		return null;
	}

	public static Map<String, String> toMap() {
		GetWayError[] ary = values();
		Map<String, String> enumMap = new HashMap<>();
        for (GetWayError getWayError : ary) {
            enumMap.put(String.valueOf(getWayError.getCode()),
                    getWayError.getMsg());
        }
		return enumMap;
	}

	@Override
	public BeeResponse tranceError(Object o) {
		return tranceError(this.code, this.msg, o);
	}
}
